<template>
  <div class="app-container">
    <!-- 顶部导航栏组件 -->
    <TopNavigation :admin-name="adminName" @logout="handleLogout" />

    <div class="content-container">
      <!-- 左侧导航栏组件 -->
      <SideNavigation :menu-items="menuItems" />

      <!-- 主内容区域 -->
      <div class="main-content">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script setup>
import {onMounted, ref} from 'vue';
import { useRouter } from 'vue-router';
import { ElMessageBox, ElMessage } from 'element-plus';
import TopNavigation from '@/components/TopNavigation.vue';
import SideNavigation from '@/components/SideNavigation.vue';

const router = useRouter();

const adminName = ref('');

onMounted(() => {
  adminName.value = localStorage.getItem('username') || 'admin';
})

const menuItems = ref([
  { id: 1, name: '首页', path: '/dashboard/homepage' },
  { id: 2, name: '用户管理', path: '/dashboard/user-management' },
  // { id: 3, name: '用户记账管理', path: '/dashboard/user-booking-management' },
  { id: 3, name: '管理员管理', path: '/dashboard/admin-management' },
  { id: 4, name: '设置', path: '/dashboard/settings' }
]);

const handleLogout = () => {
  ElMessageBox.confirm('确定要退出登录吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  })
      .then(() => {
        localStorage.clear();
        router.push('/login');
        ElMessage.success('退出成功');
      })
      .catch(() => {
        ElMessage.info('取消退出');
      });
};
</script>

<style>
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.content-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 60px);
}

.main-content {
  flex: 1;
  position: relative;
}
</style>